var t = require("../../../mybehaviors/location/location"), a = getApp();

Page({
    behaviors: [ t ],
    data: {
        language: "",
        data_info: {},
        show1: !0,
        show2: !0,
        detail: "",
        star_num: "",
        location: {},
        phone: "",
        is_cashier: !1,
        PageNameList: {},
        address: "",
        point: {
            lat: "",
            lng: ""
        },
        city: "",
        title: "",
        cityData: "",
        HOME_PAGE_URL: "plugin.hotel.frontend.hotel.get-hotel-info.get-info-by-hotel-id",
        start: "",
        end: "",
        show3: !1,
        room_arr: [],
        loading: !1,
        allLoaded: !1,
        goload: !0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        night_day: "",
        banner_img: "",
        name: "",
        catagory_name: "",
        toolbar: !1,
        wxTitie: "",
        id: "",
        ROOM_URL: "plugin.hotel.frontend.hotel.goods.get-goods-to-page"
    },
    onLoad: function(t) {
        var a = this;
        if (t.scene) {
            var e = decodeURIComponent(t.scene);
            if (console.log(e), e) {
                var o = [];
                o = e.split("&"), console.log(o);
                for (var i = 0; i < o.length; i++) {
                    var s;
                    s = o[i].split("="), console.log(s), "id" == s[0] && this.setData({
                        id: s[1]
                    });
                }
            }
        }
        t.id && this.setData({
            id: t.id
        }), t.city && this.setData({
            cityData: t.city
        }), t.start && this.setData({
            start: t.start
        }), t.end && this.setData({
            end: t.end
        }), this._getLocation(function() {
            a.getHomePageData();
        }), this.getInitTime(), this.getDays(this.data.start, this.data.end), this.initData(), 
        this.getData(), this.getCustomizeHotelHead();
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        var t = "/packageC/hotel/HotelHome/HotelHome?id=".concat(this.data.id);
        return this.data.cityData && (t = t + "&city=" + this.data.cityData), {
            path: t
        };
    },
    getHomePageData: function() {
        var t = this, e = a.getNetAddresss(t.data.HOME_PAGE_URL);
        e += "&hotel_id=" + this.data.id, e += "&lng=" + this.data.point.lng, e += "&lat=" + this.data.point.lat, 
        e += "&city_name=" + this.data.cityData, a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result && (t.setData({
                    data_info: e.data,
                    phone: e.data.mobile,
                    is_cashier: 1 == e.data.is_cashier
                }), t.getStar(e.data.star_rated));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getStar: function(t) {
        switch (t) {
          case 0:
            this.setData({
                star_num: "未评星"
            });
            break;

          case 2:
            this.setData({
                star_num: "二星级经济型"
            });
            break;

          case 3:
            this.setData({
                star_num: "三星级舒适性"
            });
            break;

          case 4:
            this.setData({
                star_num: "四星级高档型"
            });
            break;

          case 5:
            this.setData({
                star_num: "五星级豪华型"
            });
        }
    },
    getCustomizeHotelHead: function() {
        var t = this, e = "";
        try {
            var o = wx.getStorageSync("customizeHotelHead");
            o && (e = o);
        } catch (t) {}
        if (a._isTextEmpty(e)) {
            var i = a.getNetAddresss("plugin.hotel.frontend.hotel.get-hotel-info.get-custom-name");
            a._getNetWork({
                url: i,
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        t.setData({
                            PageNameList: e.data
                        }), wx.setNavigationBarTitle({
                            title: e.data.hotel_home_page ? e.data.hotel_home_page : ""
                        });
                        try {
                            wx.setStorageSync("customizeHotelHead", JSON.stringify(e.data));
                        } catch (t) {
                            console.log(t);
                        }
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        } else this.setData({
            PageNameList: JSON.parse(e)
        }), wx.setNavigationBarTitle({
            title: this.data.PageNameList.hotel_home_page
        });
    },
    gotoCashier: function() {
        wx.navigateTo({
            url: "/packageC/cashier/cashier_pay/cashier_pay?hotel_id=" + this.data.id
        });
    },
    goToAdress: function() {
        var t = this.data.data_info.latitude, e = this.data.data_info.longitude, o = this.data.data_info.hotel_name, i = a.BMapTransqqMap(parseFloat(e), parseFloat(t));
        wx.openLocation({
            latitude: i.lat,
            longitude: i.lng,
            scale: 18,
            name: o
        });
    },
    gophone: function() {
        var t = this.data.phone;
        wx.makePhoneCall({
            phoneNumber: t
        });
    },
    gotoCheckRoom: function() {
        wx.navigateTo({
            url: "/packageC/hotel/HotelChooseRoom/HotelChooseRoom?id=" + this.data.data_info.id + "&start=" + this.data.start + "&end=" + this.data.end + "&city=" + this.data.cityData
        });
    },
    toggleShow1: function() {
        this.setData({
            show1: !this.data.show1
        });
    },
    toggleShow2: function() {
        this.setData({
            show2: !this.data.show2
        });
    },
    getInitTime: function() {
        (a._isTextEmpty(this.data.start) || a._isTextEmpty(this.data.end)) && this.getTime();
    },
    getTime: function() {
        var t = new Date(), a = new Date(t.getTime() + 864e5);
        this.setData({
            start: "".concat(t.getFullYear(), "-").concat(t.getMonth() + 1 < 10 ? "0".concat(t.getMonth() + 1) : "".concat(t.getMonth() + 1), "-").concat(t.getDate() < 10 ? "0".concat(t.getDate()) : "".concat(t.getDate()))
        }), this.setData({
            end: "".concat(a.getFullYear(), "-").concat(a.getMonth() + 1 < 10 ? "0".concat(a.getMonth() + 1) : "".concat(a.getMonth() + 1), "-").concat(a.getDate() < 10 ? "0".concat(a.getDate()) : "".concat(a.getDate()))
        });
    },
    getDays: function(t, a) {
        var e, o, i;
        e = t.split("-"), o = a.split("-");
        var s = new Date(e[0], e[1] - 1, e[2]), n = new Date(o[0], o[1] - 1, o[2]);
        i = parseInt(Math.abs(s - n) / 1e3 / 60 / 60 / 24), this.setData({
            night_day: i
        });
    },
    initData: function() {
        this.setData({
            page: 1,
            total_page: 0,
            goload: !0,
            loading: !0,
            allLoaded: !1,
            isLoadMore: !0,
            room_arr: []
        });
    },
    getData: function() {
        var t = this, e = a.getNetAddresss(t.data.ROOM_URL);
        e += "&page=" + this.data.page, e += "&hotel_id=" + this.data.id, e += "&enter_at=" + this.data.start, 
        e += "&leave_at=" + this.data.end, a._getNetWork({
            url: e,
            success: function(e) {
                var o = e.data;
                1 == o.result ? (t.setData({
                    room_arr: o.data.list.data,
                    total_page: o.data.list.last_page
                }), a._isTextEmpty(t.data.banner_img) && t.setData({
                    banner_img: o.data.hotel.banner_thumb
                }), a._isTextEmpty(t.data.name) && t.setData({
                    name: o.data.hotel.hotel_name
                }), a._isTextEmpty(t.data.catagory_name) && t.setData({
                    catagory_name: o.data.hotel.has_one_category.name
                })) : wx.showToast({
                    title: o.msg,
                    icon: "none",
                    duration: 1500,
                    success: function() {
                        setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1500);
                    }
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    show2btn: function() {
        this.setData({
            show2: !0
        });
    },
    show3btn: function() {
        this.setData({
            show3: !0
        });
    },
    acceptTime: function(t) {
        var a = t.detail.type, e = t.detail.date;
        "离店" == a ? this.setData({
            end: e
        }) : "入住" == a && this.setData({
            start: e
        }), this.checkDate(a);
    },
    checkDate: function(t) {
        var e = new Date(this.data.start).getTime(), o = new Date(this.data.end).getTime();
        return a._isTextEmpty(this.data.start) ? (wx.showToast({
            title: "请先选择入住日期",
            icon: "none",
            duration: 2e3
        }), void this.setData({
            end: ""
        })) : e == o ? (wx.showToast({
            title: "入住和离店日期不能为同一天",
            icon: "none",
            duration: 2e3
        }), void this.setData({
            end: ""
        })) : e > o ? (wx.showToast({
            title: "离店日期需要大于入店日期",
            icon: "none",
            duration: 2e3
        }), void this.setData({
            end: ""
        })) : void ("离店" == t ? (this.getDays(this.data.start, this.data.end), this.setData({
            show3: !1
        })) : "入住" == t && this.setData({
            show2: !1
        }));
    },
    close: function(t) {
        var a = t.detail;
        "离店" == a ? this.setData({
            show3: !1
        }) : "入住" == a && this.setData({
            show2: !1
        });
    },
    show2closebtn: function() {
        this.setData({
            show2: !1
        });
    },
    show3closebtn: function() {
        this.setData({
            show3: !1
        });
    },
    gotoGoods: function(t) {
        var e = t.currentTarget.dataset.id;
        a._isTextEmpty(this.data.start) ? wx.showToast({
            title: "住店时间不能为空",
            icon: "none",
            duration: 2e3
        }) : a._isTextEmpty(this.data.end) ? wx.showToast({
            title: "离店时间不能为空",
            icon: "none",
            duration: 2e3
        }) : wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + e + "&start=" + this.data.start + "&end=" + this.data.end
        });
    }
});